package com.tucc.hello.leetcode.no401_800.no415;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.addStrings("123", "979"));
    }

    public String addStrings(String num1, String num2) {
        int start = 1;
        int len1 = num1.length();
        int len2 = num2.length();
        int addition = 0;
        StringBuilder result = new StringBuilder();
        while(start <= len1 || start <= len2){
            int n1 = 0;
            int n2 = 0;
            if(start <= len1){
                n1 = num1.charAt(len1 - start) - '0';
            }
            if(start <= len2){
                n2 = num2.charAt(len2 - start) - '0';
            }
            int n = n1 + n2 + addition;
            if(n > 9){
                addition = 1;
            }
            else{
                addition = 0;
            }
            result.append(n % 10);
            start ++;
        }
        if(addition > 0){
            result.append(addition);
        }
        return result.reverse().toString();
    }



}
